/**
 * Created by IntelliJ IDEA.
 * User: alexander
 * Date: 13.09.11
 * Time: 10:38
 * To change this template use File | Settings | File Templates.
 */
package com.etc {
import com.framework.math.Amath;
import com.towerdefence.gui.HealthBar;

import flash.display.Graphics;

import flash.display.Sprite;

public class HelthBar_mc extends HealthBar {

	private var _bar: Sprite = null;
	private var _barColor: Number = 0xEDE8EA;
	private var _innerColor: Number = 0x138713;
	private var _width: Number = 16;
	private var _height: Number = 5;

	public function HelthBar_mc( ) {
		super();
		_bar = new Sprite();
		addChild(_bar);
	}

	override public function gotoAndStop(frame:Object, scene:String = null):void {
		updateBar( frame as Number );
	}

	private function updateBar( fn: Number ): void{
		fn = fn < 0 ? 0 : fn;

		removeChild(_bar);
		var iw: Number = Amath.fromPercent((fn as Number) * 10,_width);
		_bar = bar( _width, iw );
		_bar.x = -_width/2;
		_bar.y = - (_height + 10 );
		addChild(_bar);
	}

	private function bar( wo: Number,  wi: Number ): Sprite {
		var o: Sprite = new Sprite();
		var g: Graphics = o.graphics;
		g.beginFill( _barColor );
		g.drawRect(0,0,wo,_height);
		g.endFill();
		g.beginFill( _innerColor );
		g.drawRect(0,0,wi,_height);
		g.endFill();
		return o;
	}
}
}
